Hi there
the beginning of my program reads:
#include <stdio.h>
#include <math.h>
main()
{
int Ca; Ca = 998;
int Cm; Cm = 1617;
and the compiler tells me:
line 6: Parse Error, expecting `'}''
'int Cm'
aborting compile
what is wrong with line 6?
Hi there
the beginning of my program reads:
#include <stdio.h>
#include <math.h>
main()
{
int Ca; Ca = 998;
int Cm; Cm = 1617;
and the compiler tells me:
line 6: Parse Error, expecting `'}''
'int Cm'
aborting compile
what is wrong with line 6?
Multiple problems:Code:main() { int Ca; Ca = 998; int Cm; Cm = 1617; and the compiler tells me:
1) Main should take this form:
int main( void )
Or this form:
int main( int argc, char *argv[] )
2) Assign your variables in the declaration, or after all variables have been declared:
int Ca = 998;
int Cm = 1617;
Or the second method:
int Ca;
int Cm;
Ca = 998;
Cm = 1617;
3) You have no closing braces
4) Main returns an int, so it should actually end up as:Code:}
Have fun.Code:return 0; }
Quzah.
Hope is the first step on the road to disappointment.
>>1) Main should take this form:
>>int main( void )
>>Or this form:
>>int main( int argc, char *argv[] )
Not necessarily. main( ) is legal in C, but not in C++.
Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah
You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie
Well technicly, this works also:Originally posted by XSquared
Not necessarily. main( ) is legal in C, but not in C++.
int main( int argc, char**argv )
However, according to the standard, unless it has changed in C99, the two forms I listed are what the standard defines.
So if you want the standard, you use the equivelant of what I listed; anything else is non-standard, implementation specific.5.1.2.2.1 Program Startup
....
It shall be defined with a return type of int and with no paramegers:
int main( void ) { /* ... */ }
or with two parameters (referred to here as argc and argv, though any names may be used, as they are local to the function in which they are declared):
int main( int argc, char *argv[]) { /* ... */ }
or equivalent) or in some other implementation-defined manner.
Quzah.
Hope is the first step on the road to disappointment.
Whoops. I was wrong.
Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah
You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie
>>int main( int argc, char *argv[] )
ok this is one of the standard, my question is that why do we pass two arguments to the main function, one as an int and one as a pointer to a char array. What are some of their use in the program?
argc == arguement count
It counts the arguements at the command line.
Like say to run your program you type
./program then argc would be 1 in your program, if you typed say ./program something then argc would be 2
argv is an array of pointers to the strings you used at the command line. argv stands for arguement vector. So if you typed ./program something argv[0] == "./program" and argv[1] == "something".
You use them so your program can accept command line arguements. That's how programs like cp, ls, etc take arguements at the command line.
Almost forgot, this is a good read, it explains it well and you should have a solid understanding of command line arguements if you work through it and understand all the code presented. It's worth it, goodluck.
http://faq.cprogramming.com/cgi-bin/...&id=1043284392
Last edited by SourceCode; 06-13-2003 at 11:39 PM.
thanks. I understand it now.